#include"../mqserver/mq_route.hpp"
#include<gtest/gtest.h>


std::unordered_map<std::string,std::string> tmpmap = {{"k1","v1"},{"k2","v2"}};

class routeTest : public testing::Test{
    public:
        void SetUp() override{

        }        
            
        void TearDown() override{
            // std::cout<<"clear..."<<std::endl;
            
        }
    public:
        
};
// binding key routing key result
// aaa              aaa     true
// aaa.bbb          aaa.bbb true
// aaa.bbb          aaa.bbb.ccc false
// aaa.bbb          aaa.ccc false
// aaa.#.bbb        aaa.bbb.ccc false
// aaa.bbb.#        aaa.ccc.bbb false
// #.bbb.ccc        aaa.bbb.ccc.ddd false
// aaa.bbb.ccc      aaa.bbb.ccc true
// aaa.*            aaa.bbb true
// aaa.*.bbb        aaa.bbb.ccc false
// *.aaa.bbb        aaa.bbb false
// #                aaa.bbb.ccc true
// aaa.#            aaa.bbb true
// aaa.#            aaa.bbb.ccc true
// aaa.#.ccc        aaa.ccc true
// aaa.#.ccc        aaa.bbb.ccc true
// aaa.#.ccc        aaa.aaa.bbb.ccc true
// #.ccc            ccc true
// #.ccc            aaa.bbb.ccc true
// aaa.#.ccc.ccc    aaa.bbb.ccc.ccc.ccc true
// aaa.#.bbb.*.bbb  aaa.ddd.ccc.bbb.eee.bbb true

TEST_F(routeTest,routing_test){
    std::vector<std::string> bindingkey = {
           "aaa",
           "aaa.bbb",
           "aaa.bbb",
           "aaa.bbb",
           "aaa.#.bbb",
           "aaa.bbb.#",
           "#.bbb.ccc",
           "aaa.bbb.ccc",
           "aaa.*",
           "aaa.*.bbb",
           "*.aaa.bbb",
           "#",
           "aaa.#",
           "aaa.#",
           "aaa.#.ccc",
           "aaa.#.ccc",
           "aaa.#.ccc",
           "#.ccc",
           "#.ccc",
           "aaa.#.ccc.ccc",
           "aaa.#.bbb.*.bbb"
    };

    std::vector<std::string> routingkey = {
       "aaa",
       "aaa.bbb",
       "aaa.bbb.ccc",
       "aaa.ccc",
       "aaa.bbb.ccc",
       "aaa.ccc.bbb",
       "aaa.bbb.ccc.ddd",
       "aaa.bbb.ccc",
       "aaa.bbb",
       "aaa.bbb.ccc",
       "aaa.bbb",
       "aaa.bbb.ccc",
       "aaa.bbb",
       "aaa.bbb.ccc",
       "aaa.ccc",
       "aaa.bbb.ccc",
       "aaa.aaa.bbb.ccc",
       "ccc",
       "aaa.bbb.ccc",
       "aaa.bbb.ccc.ccc.ccc",
       "aaa.ddd.ccc.bbb.eee.bbb",
    };
    std::vector<bool> result = {
        true,
        true,
        false,
        false,
        false,
        false,
        false,
        true,
        true,
        false,
        false,
        true,
        true,
        true,
        true,
        true,
        true,
        true,
        true,
        true,
        true
    };

    for(auto& bk :bindingkey){
        ASSERT_EQ( mq::Router::IsLegalBindingkey(bk),true);
    }

    for(auto& rk :routingkey){
        ASSERT_EQ( mq::Router::IsLegalRoutingkey(rk),true);
    }

    for(int i = 0;i < bindingkey.size();i++){
        // bool re = ;
        // LOG_DEBUG("rkey: %s , bkey: %s , result: %d",routingkey[i].c_str(),bindingkey[i].c_str(),static_cast<int>(result[i]));
        ASSERT_EQ(mq::Router::route(mq::ExchangeType::TOPIC,routingkey[i],bindingkey[i]),result[i]);
    }
}

int main(int argc,char* argv[]){
    testing::InitGoogleTest(&argc,argv);
    // testing::AddGlobalTestEnvironment(new HostTest);
    return RUN_ALL_TESTS();
}
